define(["angularAMD", "moment"], function (angularAMD, moment) {
    angularAMD.service('Inject01Service', ['$rootScope', '$filter', '$translate', 'config', 'MMWService', '$mdDialog','$calculater', "$gallery",
        function ($rootScope, $filter, $translate, config, $MMWService, $mdDialog,$calculater, $gallery) {
            /**
             * options = {
             *     machine_no: '', // request用
                   plotInfo : '', // request用
             *     recipe_list: {} // 從 B0205 傳來給此頁面(Inject01)使用
             *     feedback: function
             * }
            **/

            this.init = function (options, feedback) {

                // 取得 recipe參數list
                function recipe_list_info_get(callback){
                    // var data = {
                    //     recipe_list: [
                    //         {
                    //             recipe_phase: '1',
                    //             recipe_name: '溫度',
                    //             recipe_segment_qty: '1',
                    //             actual_value: 50,
                    //             lower_limit_value: 40,
                    //             standard_value: 45,
                    //             upper_limit_value: 48,
                    //             param_no: '001',
                    //         },
                    //         {
                    //             recipe_phase: '2',
                    //             recipe_name: '溫度2',
                    //             recipe_segment_qty: '2',
                    //             actual_value: 50,
                    //             lower_limit_value: 40,
                    //             standard_value: 45,
                    //             upper_limit_value: 48,
                    //             param_no: '002',
                    //         }
                    //     ],
                    //     check_type: '1', // check_type(強制進站顯示)： 1 = 顯示 ; 0 = 不顯示
                    //     program_no: 'ITM01',
                    //     version_no: '001',
                    // };
                    // if (callback)
                    //     callback(data);

                    var content = {
                        machine_no: options.machine_no,
                        lot_no: options.plotInfo.plot_no,
                        op_no: options.plotInfo.op_no
                    };
                    $MMWService.sendToServer({
                        uri: 'ServicesSTD.Module_INJECT.injection_recipe_check_fail_info',
                        content: content,
                        success: function (data) {
                            if (callback)
                                callback(data);
                        }
                    });
                };

                var openDialog = function(data){
                    $mdDialog.dialog(
                        'module/moduleInject/program/Inject01/Inject01.html',
                        function (dialog) {
                            return {
                                css_url: 'module/moduleInject/program/Inject01/Inject01.css',
                                plot_no: options.recipe_list.plot_no,
                                machine_no: options.recipe_list.machine_no,
                                machine_name: options.recipe_list.machine_name,
                                product_no: options.recipe_list.product_no,
                                product_name: options.recipe_list.product_name,
                                program_no: data.program_no,
                                version_no: data.version_no,
                                recipe_list: data.recipe_list,
                                check_type: data.check_type,
                                back: function(){
                                    dialog.hide();
                                },
                                cancelCheckIn: function(){
                                    dialog.hide();
                                },
                                forceCheckIn: function(){
                                    if(feedback){
                                        feedback(options, dialog);
                                    }
                                }
                            };
                        }
                    );
                };

                recipe_list_info_get(function(data){
                    openDialog(data);
                });
                
            };
        }]);
});
